//
//  HomeMainV.m
//  UHealth
//
//  Created by gjtxz on 14/12/29.
//  Copyright (c) 2014年 gjtx. All rights reserved.
//

#import "HomeMainV.h"


@interface HomeMainV ()

@end

@implementation HomeMainV

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self DrawViewWithFrame:frame];
    }
    return self;
}

-(void)DrawViewWithFrame:(CGRect)frame
{
    UIView *blueView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, 100)];
    blueView1.backgroundColor = kBlueColor;
    [self addSubview:blueView1];
    
   
    _userBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 25, 30, 30)];
    _userBtn.tag = 1;
    [_userBtn setBackgroundImage:[UIImage imageNamed:@"burger"] forState:UIControlStateNormal];
    [self addSubview:_userBtn];
    
//    _eBtn = [[UIButton alloc]initWithFrame:CGRectMake(frame.size.width-30-20, 30, 20 , 20)];
//    _eBtn.tag = 2;
//    [_eBtn setBackgroundImage:[UIImage imageNamed:@"electricity"] forState:UIControlStateNormal];
//    [self addSubview:_eBtn];
    
    _BLEBtn = [[UIButton alloc]initWithFrame:CGRectMake(frame.size.width-40, 25, 30 , 30)];
    _BLEBtn.tag = 3;
    [_BLEBtn setBackgroundImage:[UIImage imageNamed:@"bluetooth"] forState:UIControlStateNormal];
    [self addSubview:_BLEBtn];
    
    NSArray *segArray = [[NSArray alloc]initWithObjects:kLocal(@"Current"),kLocal(@"Chart"),kLocal(@"Report"),nil];
    UISegmentedControl *homeSeg = [[UISegmentedControl alloc]initWithItems:segArray];
    homeSeg.layer.masksToBounds = YES;
    [homeSeg.layer setCornerRadius:5];
    homeSeg.frame = CGRectMake(50,25,frame.size.width-100, 28);
    homeSeg.selectedSegmentIndex = 0;
    homeSeg.backgroundColor = [UIColor clearColor];
    homeSeg.tintColor = kWhiteBlueColor;
    [homeSeg setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
    [homeSeg setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];
    [homeSeg addTarget:self action:@selector(segmentAction:)forControlEvents:UIControlEventValueChanged];  //添加委托方法
    [self addSubview:homeSeg];
    
    //日期
    _ratView = [[RatView alloc]initWithFrame:CGRectMake(10, 65, frame.size.width-20, 23)];
//    [_ratView RefreshViewForCount:4];
    [self addSubview:_ratView];
    
    //--------------------------分割线----------------------------//
    
    CGRect f =  CGRectMake(0, 100, frame.size.width, frame.size.height - 100);
    _currentV = [[CurrentV alloc]initWithFrame:f];
    _chartV = [[ChartV alloc]initWithFrame:f];
    _reportV = [[ReportV alloc]initWithFrame:f];
    
    //添加3个不同视图
    [self addSubview:_currentV];
    [self addSubview:_chartV];
    [self addSubview:_reportV];
    _currentV.hidden = NO;
    _chartV.hidden = YES;
    _reportV.hidden = YES;
}


#pragma mark - func

-(void)segmentAction:(UISegmentedControl *)Seg{
    
    NSInteger Index = Seg.selectedSegmentIndex;
    kDebug(@"Index %li", (long)Index);
    switch (Index) {
        case 0:{
            _currentV.hidden = NO;
            _chartV.hidden = YES;
            _reportV.hidden = YES;
        }
            break;
        case 1:{
            _currentV.hidden = YES;
            _chartV.hidden = NO;
            _reportV.hidden = YES;
        }
            break;
        case 2:{
            _currentV.hidden = YES;
            _chartV.hidden = YES;
            _reportV.hidden = NO;
        }
            break;
    }
}






@end
